// custom-tab-bar/index.js
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import { store } from '../store/index'
Component({
  // 组件中引入mobx
  behaviors: [storeBindingsBehavior],
  storeBindings: {
    store,
    fields: {
      cartCount: 'cartCount'
    }
  },
  // 监听cart数量变化
  observers: {
    'cartCount': function(newCartCount) {
      this.setData({
        'list[2].info': newCartCount
      })
    }
  },

  options: {
    styleIsolation: "shared"
  },
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    active: 0,
    list: [
      {
        pagePath: "/pages/home/home",
        text: "首页",
        iconPath: "../static/home.png",
        selectedIconPath: "../static/home-a.png"
      },
      {
        pagePath: "/pages/cate/cate",
        text: "分类",
        iconPath: "../static/category.png",
        selectedIconPath: "../static/category-a.png"
      },
      {
        pagePath: "/pages/cart/cart",
        text: "购物车",
        iconPath: "../static/cart.png",
        selectedIconPath: "../static/cart-a.png",
        info: 2        
      },
      {
        pagePath: "/pages/profile/profile",
        text: "我的",
        iconPath: "../static/profile.png",
        selectedIconPath: "../static/profile-a.png"
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(event) {
      // console.log(event)
      this.setData({
        active: event.detail
      })
      // wx.switchTab({
      //   url: this.data.list[event.detail].pagePath
      // })
      wx.reLaunch({
        url: this.data.list[event.detail].pagePath,
      })
    }
  }
})
